package com.zmn.mcc.business.impl.staff;

import com.zmn.common.dto.LoginStaff;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.mcc.business.interfaces.staff.StaffChangeLogBService;
import com.zmn.mcc.business.interfaces.staff.ip.StaffIpInfoBService;
import com.zmn.mcc.common.constant.StaffChangeLogConsts;
import com.zmn.mcc.common.dictionary.StaffDict;
import com.zmn.mcc.model.entity.log.IpInfo;
import com.zmn.mcc.model.entity.staff.staffchangelog.StaffChangeLog;
import com.zmn.mcc.services.interfaces.staff.StaffDpermitService;
import com.zmn.mcc.services.interfaces.staff.staffchangelog.StaffChangeLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 描述: 员工异动基础接口类
 *
 * @author guoqiao
 * @since 2021-03-08 11:28:02
 */
@Service
public class StaffChangeLogBServiceImpl implements StaffChangeLogBService {

    protected Logger logger = LoggerFactory.getLogger(StaffChangeLogBServiceImpl.class);

    @Resource
    private StaffChangeLogService staffChangeLogService;

    @Resource
    StaffIpInfoBService staffIpInfoBService;


    @Override
    public void insertAuthLog(Integer staffId, LoginStaff loginStaff, String ip, String str) {

        IpInfo ipInfo = staffIpInfoBService.locationByIP(ip);
        String abutmenterCity = null;
        if (Objects.nonNull(ipInfo)) {
            abutmenterCity = ipInfo.getProvince() + "-" + ipInfo.getCity();
        }

        StaffChangeLog staffChangeLog = StaffChangeLog.builder()
                .staffId(staffId)
                .beforContent("-")
                .afterContent("编辑" + str)
                .abutmenterId(loginStaff.getStaffId())
                .abutmenter(loginStaff.getRealName())
                .abutmenterDeptId(loginStaff.getDeptId() + "")
                .abutmenterDeptName(loginStaff.getDeptName())
                .changeType(StaffChangeLogConsts.CHANGE_TYPE_AUTH)
                .createTime(DateUtil.getNow())
                .ip(ip)
                .abutmenterCity(abutmenterCity)
                .build();
        staffChangeLogService.insert(staffChangeLog);

    }
}

